package com.stgy.lease.web.admin.task;

import com.stgy.lease.web.admin.service.LeaseAgreementService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * ClassName:STGYAdminTask
 * Package:com.stgy.lease.web.admin.task
 * Description:
 *
 * @Author:helei
 * @Create:2024/9/3 - 11:35
 */
@Component
@EnableScheduling //开启定时任务功能
public class STGYAdminTask {

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    //second
    //minute
    //hour
    //day of month
    //month
    //day of week
    //cron表达式由7位组成 最后两位(周和年)不能一样，一般最后一位使用问号
    //0 * * * * MON-FRI springtask不支持年 只使用前6位
    //标注的方法就是一个定时任务
//    @Scheduled(cron = "0/5,11,22,33 41 * * * *")//0/5 0秒开始每过5秒
    //在线生成cron表达式
//    @Scheduled(cron = "*/5 * * * * *")//*/5 每过5秒
    //空闲时 执行预约状态的检查 更新状态
    @Scheduled(cron = "0 0 3 * * *")
    public void checkAgreementStatus() {
//        System.out.println(new DateTime().toString("yyyy-MM-dd HH:mm:ss"));
        leaseAgreementService.checkAgreementStatus();
    }

    public static void main(String[] args) {
        //默认使用当前时间创建对象：获取0点0分0秒的 时间毫秒数
        DateTime dateTime1 = new DateTime().withTimeAtStartOfDay();
        System.out.println(dateTime1.toString("yyyy-MM-dd HH:mm:ss"));

        DateTime dateTime2 = new DateTime("2024-09-01").withTimeAtStartOfDay();
        System.out.println(dateTime2.toString("yyyy-MM-dd HH:mm:ss"));
        System.out.println(dateTime1.isAfter(dateTime2));
        System.out.println(dateTime2.plusDays(2).isAfter(dateTime1));

    }
}
